<?php
namespace Admin\Controller;
use Think\Controller;
class PublicController extends Controller {
	/**
	 * 登录
	 */
	public function login() {
		if(IS_POST)
		{
			$admin=M("admin");
			$data['admin_name']=$_POST['admin_name'];
			$data['admin_pwd']=md5($_POST['admin_pwd']);
			if($this->check_verify($_POST['code'])){
			if($admin->where($data)->find())
			{
				$data=$admin->where($data)->find();
				session('admin',$data['admin_name']);
				session('nickname',$data['admin_nickname']);  
				session('user',$data);  
				redirect(U("index/index"));
			}
			else 
			{
			$this->error("账号密码错误");
			}
			}
			else 
			$this->error("验证码错误");
		}
		else {
			$this->display();
		}
		
	}
	/**
	 * 注销
	 */
	public function logout(){
		session(null); // 清空当前的session
		redirect(U("index/index"));
	
	}
	/**
	 * 验证验证码
	 * @param 验证码
	 * @return boolean
	 */
	public function check_verify($code) {
		$verify = new \Think\Verify ();
		return $verify->check ( $code );
	}
	/**
	 * 生成验证码
	 */
	public function verify() {
		
		$Verify = new \Think\Verify ();
		$Verify->fontSize = 30;
		$Verify->length = 6;
		$Verify->useNoise = false;
		$Verify->fontttf = '5.ttf'; 
		$Verify->entry ();
	}
}